package com.ruoyi.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamExamination;
import com.ruoyi.exam.service.IExamExaminationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试Controller
 * 
 * @author ba7lgj
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/exam/examination")
public class ExamExaminationController extends BaseController
{
    @Autowired
    private IExamExaminationService examExaminationService;

    /**
     * 查询考试列表
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamExamination examExamination)
    {
        startPage();
        List<ExamExamination> list = examExaminationService.selectExamExaminationList(examExamination);
        return getDataTable(list);
    }

    /**
     * 导出考试列表
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:export')")
    @Log(title = "考试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamExamination examExamination)
    {
        List<ExamExamination> list = examExaminationService.selectExamExaminationList(examExamination);
        ExcelUtil<ExamExamination> util = new ExcelUtil<ExamExamination>(ExamExamination.class);
        util.exportExcel(response, list, "考试数据");
    }

    /**
     * 获取考试详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:query')")
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") Long examId)
    {
        return success(examExaminationService.selectExamExaminationByExamId(examId));
    }

    /**
     * 新增考试
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:add')")
    @Log(title = "考试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamExamination examExamination)
    {
        return toAjax(examExaminationService.insertExamExamination(examExamination));
    }

    /**
     * 修改考试
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:edit')")
    @Log(title = "考试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamExamination examExamination)
    {
        return toAjax(examExaminationService.updateExamExamination(examExamination));
    }

    /**
     * 删除考试
     */
    @PreAuthorize("@ss.hasPermi('exam:examination:remove')")
    @Log(title = "考试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Long[] examIds)
    {
        return toAjax(examExaminationService.deleteExamExaminationByExamIds(examIds));
    }
}
